# 导包
import time

import pytest
from selenium.webdriver.common.by import By
from common.utilss import get_driver, quit_driver
from page.add_godds import AddGoddspage
import config
import pytest
import time


# 创建测试类
class TestLoginPage:
    # 类前置方法
    def setup_class(self):
        # 类前置代码只被执行一次
        # 获取浏览器驱动
        self.driver = get_driver()
        # 实例化页面对象
        self.add_goods_page = AddGoddspage()

    def teardown_class(self):
        # 类后置代码只被执行一次
        # 关闭浏览器驱动
        quit_driver(self.driver)

    def setup_method(self):
        # 方法前置代码被执行一次
        # 打开测试页
        self.driver.get("http://www.litemall360.com:8081")

    def teardown_method(self):
        # 截图保存
        # self.driver.get_screenshot_as_file(config.BASE_PATH + f"/image/login-{randint(1000, 9999)}.png")
        self.driver.get_screenshot_as_file(config.BASE_DIR + f"/image/login-{time.strftime('%Y%m%d%H%M%S')}.png")
        # 方法后置代码被执行一次
        time.sleep(3)

    # 登录成功
    @pytest.mark.run(order=3)
    def test01_login_success(self):
        self.add_goods_page.login(self.driver, username="admin123", password="admin123")
        pass

    # 登录失败（账号为空）
    @pytest.mark.skip(reason="bug")
    def test02_login_fail_username_empty(self):
        # bug
        # self.add_goods_page.login(self.driver, username="", password="admin123")
        pass

    # 登录失败（账号不存在）
    @pytest.mark.run(order=1)
    def test03_login_fail_username_not_exist(self):
        self.add_goods_page.login(self.driver, username="admin123456", password="admin123")

    # 登录失败（密码为空）
    @pytest.mark.skip(reason="bug")
    def test04_login_fail_password_empty(self):
        # bug
        #  self.add_goods_page.login(self.driver, username="admin123", password="")
        pass

    # 登录失败（密码错误）
    @pytest.mark.run(order=2)
    def test05_login_fail_password_error(self):
        self.add_goods_page.login(self.driver, username="admin123", password="admin123456")



